package com.golxen.framework.netty.session.base;


import com.golxen.framework.PBPacket.PBPacket;

import java.util.concurrent.atomic.AtomicInteger;

public abstract class AbstractSession {

	private static final AtomicInteger tId = new AtomicInteger();

	private int tempId = tId.getAndIncrement();

	private long id; // 连接集合中的索引


	private long crossCheckAliveTime; // 跨服验证存活的时间

	public long getCrossCheckAliveTime() {
		return crossCheckAliveTime;
	}

	public void setCrossCheckAliveTime(long crossCheckAliveTime) {
		this.crossCheckAliveTime = crossCheckAliveTime;
	}

	public int getTempId() {
		return tempId;
	}

	public void setTempId(int tempId) {
		this.tempId = tempId;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	/** session 是否有效 **/
	public boolean isAlive() {
		return true;
	}

	public abstract void write(PBPacket msg);

	public void flush() {

	}

	public abstract void close();

	@Override
	public String toString() {
		return "Session [tempId=" + tempId + ", id=" + id + ", crossCheckAliveTime="
				+ crossCheckAliveTime + "]";
	}
}
